package com.bawei.yangzongcai___chenmei.BlankFragment.Blanck2;


import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.PopupWindow;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.StaggeredGridLayoutManager;

import com.bawei.yangzongcai___chenmei.Adpter.QAQadpterActivity3;
import com.bawei.yangzongcai___chenmei.JavaClass.LianxiClass;
import com.bawei.yangzongcai___chenmei.MVC.BsaeFragment;
import com.bawei.yangzongcai___chenmei.R;
import com.bawei.yangzongcai___chenmei.SQL.SQLyongyong;
import com.blankj.utilcode.util.ToastUtils;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.listener.OnItemChildLongClickListener;

import java.util.ArrayList;
import java.util.List;


public class BlankFragmentQAQ6 extends BsaeFragment implements OnItemChildLongClickListener {
    QAQadpterActivity3 qaq3;
    SQLiteDatabase readableDatabase;
    private RecyclerView qaq6rv;
    List<LianxiClass> lianxiClasses;
    @Override
    public int bandLayout() {
        return R.layout.fragment_blank_fragment_qaq6;
    }

    @Override
    public void initView() {


        qaq6rv = findbandid(R.id.qaq6rv);
        qaq6rv.setLayoutManager(new StaggeredGridLayoutManager(1,StaggeredGridLayoutManager.VERTICAL));
    }

    @Override
    public void initDate() {

        SQLyongyong sqLyongyong = new SQLyongyong(getActivity(),"chenmei.dp",null,1);
        readableDatabase = sqLyongyong.getReadableDatabase();
        Cursor chenmei = readableDatabase.query("chenmei", null, null, null, null, null, null);
        lianxiClasses = new ArrayList<>();
        while (chenmei.moveToNext())
        {
            String tile = chenmei.getString(chenmei.getColumnIndex("tile"));
            String decs = chenmei.getString(chenmei.getColumnIndex("decs"));
            String img = chenmei.getString(chenmei.getColumnIndex("img"));
          LianxiClass lianxi = new LianxiClass(tile,decs,img);
          lianxiClasses.add(lianxi);
        }

        qaq3 = new QAQadpterActivity3(lianxiClasses);
        qaq3.setOnItemChildLongClickListener(this);
        qaq6rv.setAdapter(qaq3);

    }


    @Override
    public boolean onItemChildLongClick(@NonNull BaseQuickAdapter adapter, @NonNull View view, final int position) {
        switch (view.getId())
        {
            case R.id.yangchen3_img:
                final PopupWindow popupWindow = new PopupWindow(getActivity());
                popupWindow.setHeight(500);
                popupWindow.setWidth(250);
                popupWindow.setOutsideTouchable(true);
                final View windows = LayoutInflater.from(getActivity()).inflate(R.layout.pupuwindows, null);
                popupWindow.setContentView(windows);
                popupWindow.showAsDropDown(view, Gravity.TOP,0,0);
                windows.findViewById(R.id.pupuwindows_ShanChu).setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        ToastUtils.showShort("数据已删除");
                        readableDatabase.execSQL("delete from chenmei where img=?",new Object[]{lianxiClasses.get(position).getImg()});
                        lianxiClasses.remove(position);
                        qaq3.notifyDataSetChanged();
                    }
                });
                windows.findViewById(R.id.aiyigeren).setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        ToastUtils.showShort("爱一个人");
                    }
                });

                windows.findViewById(R.id.wenyiduohua).setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        ToastUtils.showShort("吻一朵花");
                    }
                });

                break;
        }
        return false;
    }
}
